package flc.ast.dialog;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.databinding.DialogDnsBinding;
import flc.ast.databinding.DialogIpQueryBinding;
import stark.common.apis.ApiManager;
import stark.common.apis.base.IpAddrBean;
import stark.common.base.IReqRetCallback;
import stark.common.basic.base.BaseSmartDialog;

public class IpQueryDialog extends BaseSmartDialog<DialogIpQueryBinding> implements View.OnClickListener {

    public IpQueryDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_ip_query;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.tvCancel.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);
        if (NetworkUtils.isWifiConnected()) {
            startQuery(NetworkUtils.getIpAddressByWifi());
        } else {
            startQuery(NetworkUtils.getIPAddress(true));
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvCancel:
            case R.id.tvConfirm:
                dismiss();
                break;
            default:
                break;
        }
    }

    //开始查询
    private void startQuery(String ip) {
        mDataBinding.tvIpInfo.setText(ip);
        mDataBinding.tvNetInfo.setText(NetworkUtils.getNetworkOperatorName());
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void click();
    }
}
